
package com.vsct.maia.auditl;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;


/** Example resource class hosted at the URI path "/myresource"
 */
//Toutes les requetes amener ici!
@Path("/stat")
public class ResourceManager {
	
    /** Method processing HTTP GET requests, producing "text/plain" MIME media
     * type.
     * @return String that will be send back as a response of type "text/plain".
     */
    @GET
    @Path("execTimeByCriteria")
    @Produces(MediaType.APPLICATION_JSON)
    //@Produces("application/json,text/javascript")
	public String getChartData(
			@QueryParam("services") List<String> services,
			@QueryParam("dateDebut") String dateDebut,
			@QueryParam("dateFin") String dateFin,
			@QueryParam("groupBy") String groupBy,
			@QueryParam("percentile") String percentile,
			@QueryParam("callback") String callback) {
     	
    	TableBuilderJson tb = new TableBuilderJson();   	
    	String serie =  tb.getChartDataJson(services,dateDebut,dateFin,groupBy,percentile);    	   	
    	return callback+"("+serie+")"; 
    }
	
    @GET
    @Path("minmaxDate")
    @Produces(MediaType.TEXT_PLAIN)
    public String getMinMaxDate(){
    	DataManager str = new DataManager();
    	return str.getMinMaxDate();
    }
    
    @GET
    @Path("serviceTable")
    @Produces(MediaType.APPLICATION_JSON)
    public String getServiceTable(
    		@QueryParam("services") List<String> services,
			@QueryParam("dateDebut") String dateDebut,
			@QueryParam("dateFin") String dateFin,
			@QueryParam("percentile") String percentile,
			@QueryParam("callback") String callback) {
    	
	   DataManager svd = new DataManager();
	  
	   String ligne = svd.getServTable(services,dateDebut,dateFin,percentile);
	   
    	return callback+"("+ligne+")"; 
    }
    
    @GET
    @Path("methodTable")
    @Produces(MediaType.APPLICATION_JSON)
    public String getMethodTable(
    		@QueryParam("services") List<String> services,
			@QueryParam("dateDebut") String dateDebut,
			@QueryParam("dateFin") String dateFin,
			@QueryParam("percentile") String percentile,
			@QueryParam("callback") String callback) {
    	
	   DataManager svd = new DataManager();	
    	String ligne = svd.getMethodTable(services,dateDebut,dateFin,percentile);
    	return callback+"("+ligne+")"; 
    }
    
    @GET
    @Path("errorsTable")
    @Produces(MediaType.APPLICATION_JSON)
    public String getErrorsTable(
    		@QueryParam("services") List<String> services,
			@QueryParam("dateDebut") String dateDebut,
			@QueryParam("dateFin") String dateFin,
			@QueryParam("callback") String callback) {
    	
	    DataManager svd = new DataManager();	
    	String table = svd.getErrorsTable(services,dateDebut,dateFin);
    	if(table==null){
    		System.out.println("ResourceManager.getErrorsTable: "
    				+ "table is null");
    		return null;
    		}
    	return callback+"("+table+")"; 
    }
}





